import time
import setting.qu as pya
import setting.ran as pyb
import setting.xie as pyc

class Tingxie:
    def __init__(self):
        print('''欢迎来到听写框架组织旗下项目~

组织URL：https://gitcode.com/tingxie
''')

    def main(self):
        def ting(item):
            yes, no, cuo = 0, 0, {}
            for i in item:
                python = input(item[i] + '：')
                if python in i:
                    print('对喽~')
                    yes += 1
                else:
                    print('错喽错喽！')
                    no += 1
                    cuo[item[i]] = i
            print('end~\n')
            if no == 0:
                print('哇塞！全对~\n\n')
            else:
                print('一共对' + str(yes) + '个，错' + str(no) + '个')
                print('不扎实' + str(no) + '个！巩固错题start~\n')
                gai(cuo)

        def gai(item):
            global ercuo, cuocount
            yes, no = 0, 0
            for i in item:
                python = input(i + '：')
                if item[i] == python:
                    print('对喽~')
                    yes += 1
                else:
                    print('错喽错喽！')
                    no += 1
                    cuocount += 1
                    ercuo[i] = item[i]
            print('end~')
            if yes == 0:
                print('内个，全错！\n\n')
            elif yes != 0 and no != 0:
                print('一共对' + str(yes) + '个，错' + str(no) + '个')
            else:
                print('哇塞~全对！')

        qu = pya.q()
        if qu[0] == 'error':
            print('抱歉，系统出现异常情况，程序退出~')
        else:
            print('\n第' + qu[1] +'单元~')
            qu = qu[0]
            b = qu['unit']
            count = 1
            for c in b:
                print('\n\n' + b[c] + ' start~\n')
                o = qu['txt']
                p = o[b[c]]
                item = pyb.huan(p)
                true = ting(item)
                int(count)
                count += 1
            if cuocount != 0:
                print('\n有' + str(cuocount) + '个二错单词，下面是答案~')
                pyc.xie(ercuo)
            else:
                print('哇塞~全对！')

if __name__ == "__main__":
    ercuo = {}
    cuocount = 0
    tingxie = Tingxie()
    tingxie.main()
    time.sleep(10)
